package cn.highedu.spring.config;

import cn.highedu.spring.bean15.AccountRepository;
import cn.highedu.spring.bean15.JdbcAccountRepository;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
@ComponentScan("cn.highedu.spring.bean15")
public class Application6Config {

    @Bean
    public DataSource dataSource() {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        return dataSource;
    }

     @Bean(initMethod = "populateCache", destroyMethod = "flushCache")
     public JdbcAccountRepository accountRepository(){
         return new JdbcAccountRepository(dataSource());
     }

}
